

## Working directory for replication
setwd("E:/finalidealreplication/")

## Load EDM ideal point models
library(edmideal)

## Load initial values from one-cutpoint model
## Generated from average value produced by pilot chain
load("init.mean.R")
load("init.sd.R")

## Load signature matrix and sponsor IDs
mpinc98.v4 <- as.matrix(read.csv("mpinc98.v4.csv", row.names=1))
sponsorchar <- read.csv("sponsors.csv", row.names=1)
sponsor.vector98 <- sponsorchar[,1]

## Construct random starting values centered at initial values
ideal.start <- rnorm(length(mean.ideal), mean.ideal, sd.ideal*3)
propensity.start <- rnorm(length(mean.propensity), mean.propensity, 
sd.propensity*3)
statusquo.start <- rnorm(length(mean.statusquo), mean.statusquo, 
sd.statusquo*3)
motion.start <- rnorm(length(mean.motion), mean.motion, sd.motion*3)

## Ensure that constrained legislator has negative starting value
if(ideal.start[32] >= 0){ideal.start[32] <- -.1}

## Run chain for 120000 iterations, discarding first 20000 and saving every 100th iteration thereafter
condor5slice <- NewIdealSlice(mpinc98.v4, sponsor.vector98, 
negative="Benn/Tony", burnin=20000, 
			thin=100, sample=1000, 
			initial.idealpoints = ideal.start, 
			initial.propensity = propensity.start, 
			initial.statusquo = statusquo.start, 
			initial.motion = motion.start,
			verbose=1000)
 

save(condor5slice, file="condor5slice.RData")

## Continue chain for 100000 additional iterations, saving every 100th iteraction

ideal.start <- condor5slice[[1]][1000,]
propensity.start <- condor5slice[[2]][1000,]
statusquo.start <- condor5slice[[3]][1000,]
motion.start <- condor5slice[[4]][1000,]


condor15slice <- NewIdealSlice(mpinc98.v4, sponsor.vector98, 
negative="Benn/Tony", burnin=0, 
			thin=100, sample=1000, 
			initial.idealpoints = ideal.start, 
			initial.propensity = propensity.start, 
			initial.statusquo = statusquo.start, 
			initial.motion = motion.start,
			verbose=1000)
 

save(condor15slice, file="condor15slice.RData")

## Continue chain for 100000 additional iterations, saving every 100th iteraction
ideal.start <- condor15slice[[1]][1000,]
propensity.start <- condor15slice[[2]][1000,]
statusquo.start <- condor15slice[[3]][1000,]
motion.start <- condor15slice[[4]][1000,]


condor25slice <- NewIdealSlice(mpinc98.v4, sponsor.vector98, 
negative="Benn/Tony", burnin=0, 
			thin=100, sample=1000, 
			initial.idealpoints = ideal.start, 
			initial.propensity = propensity.start, 
			initial.statusquo = statusquo.start, 
			initial.motion = motion.start,
			verbose=1000)
 

save(condor25slice, file="condor25slice.RData")


## Continue chain for 100000 additional iterations, saving every 100th iteraction
ideal.start <- condor25slice[[1]][1000,]
propensity.start <- condor25slice[[2]][1000,]
statusquo.start <- condor25slice[[3]][1000,]
motion.start <- condor25slice[[4]][1000,]


condor35slice <- NewIdealSlice(mpinc98.v4, sponsor.vector98, 
negative="Benn/Tony", burnin=0, 
			thin=100, sample=1000, 
			initial.idealpoints = ideal.start, 
			initial.propensity = propensity.start, 
			initial.statusquo = statusquo.start, 
			initial.motion = motion.start,
			verbose=1000)
 

save(condor35slice, file="condor35slice.RData")






